import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/user/login',
    method: 'post',
    data: data
  })
}

export function register(form) {
  var data = JSON.parse(JSON.stringify(form))
  data.roles = JSON.stringify(data.roles)
  return request({
    url: '/user/register',
    method: 'post',
    data: data
  })
}

export function getInfo(token) {
  return request({
    url: '/user/info',
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: '/user/logout',
    method: 'post'
  })
}

export function UsersGets() {
  return request({
    url: '/users',
    method: 'get'
  })
}

export function usersGet(username) {
  return request({
    url: '/users/' + username,
    method: 'get'
  })
}

export function UsersEdit(form) {
  var data = JSON.parse(JSON.stringify(form))
  data.roles = JSON.stringify(data.roles)
  return request({
    url: '/users',
    method: 'put',
    data
  })
}

export function UsersDelete(username) {
  return request({
    url: '/users/' + username,
    method: 'delete'
  })
}
